﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VideoServer.Helpers;

namespace VideoServer.ViewModel.Helpers
{
    //保存视频数据文件类
    public class SaveVideoFile
    {
        public static string CreateFile(string id)
        {
            string savePath = SystemSettingHelper.GetFileSaveSettingValue("VideoSavePath");
            try
            {
                if (!Directory.Exists(@savePath))
                {
                    Directory.CreateDirectory(@savePath);
                }
                string fullFileName = @savePath + "\\" + id + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss") + ".bin";
                return fullFileName;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
        //写数据
        public static void WriteData(byte[] data, string fullFileName)
        {
            if (fullFileName != null)
            {
                using (FileStream fs = new FileStream(fullFileName, FileMode.Append))
                {
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        bw.Write(data);
                    }
                }
            }
        }
   
    }
}
